package com.mine.distinctionteam.ui.home.adapter;
import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.mine.distinctionteam.R;
import com.mine.distinctionteam.bean.home.ItemsBean;
import com.mine.distinctionteam.ui.good.GoodsActivity;


import java.util.List;
/**
 *
 */
public class ItemListViewRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Context mContext;
    private List<ItemsBean> list;
    private LayoutInflater inflater;
    public ItemListViewRecyclerViewAdapter(Context mContext, List<ItemsBean> list ){
        this.mContext=mContext;
        this.list=list;
        inflater= (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view=inflater.inflate(R.layout.item_fragment_home_listview_recyclerview,parent,false);
        return new ViewHolder(view);
    }
    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ((ViewHolder)holder).textView_item_fragment_home_listView_recyclerView_name.setText(""+list.get(position).getName());
        ((ViewHolder)holder).textView_item_fragment_home_listView_recyclerView_price.setText(""+list.get(position).getPrice());
        Glide.with(mContext).load(list.get(position).getImage()).into(((ViewHolder)holder).imageView_item_fragment_home_listView_recyclerView);
        getId(list.get(position).getAction().getGoodsId(),(ViewHolder)holder);
    }
    @Override
    public int getItemCount() {
        return list.size();
    }
    class ViewHolder extends RecyclerView.ViewHolder {
        private ImageView imageView_item_fragment_home_listView_recyclerView;
        private TextView textView_item_fragment_home_listView_recyclerView_name;
        private TextView textView_item_fragment_home_listView_recyclerView_price;

        public ViewHolder(View itemView) {
            super(itemView);
            imageView_item_fragment_home_listView_recyclerView= (ImageView) itemView.findViewById(R.id.imageView_item_fragment_home_listView_recyclerView);
            textView_item_fragment_home_listView_recyclerView_name= (TextView) itemView.findViewById(R.id.textView_item_fragment_home_listView_recyclerView_name);
            textView_item_fragment_home_listView_recyclerView_price= (TextView) itemView.findViewById(R.id.textView_item_fragment_home_listView_recyclerView_price);
        }
    }
    public void getId(final int id,ViewHolder holder) {
        holder.imageView_item_fragment_home_listView_recyclerView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(mContext, GoodsActivity.class);
                intent.putExtra("id", "" + id);
                mContext.startActivity(intent);
            }
        });
    }
}
